/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.feiyue.basic.server.db;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import android.content.Context;

import com.feiyue.basic.server.cache.DiskLruCache;
import com.info.runninginfo.ExceptionManager;

public class NovelDB
{

    public static void copyDatabaseFile(Context context)
    {
        File file;
        file = new File((new StringBuilder("/data/data/")).append(context.getPackageName()).append("/databases").toString());
        if (!file.exists()) {
            file.mkdir();
        }
        
        File file1 = new File(file, "novel");
        if (!file1.exists()) {
            InputStream inputstream;
            inputstream = null;
            byte abyte0[];
            FileOutputStream fileoutputstream1 = null;
            
            try {
                file1.createNewFile();
                inputstream = context.getAssets().open("novel");
                abyte0 = new byte[inputstream.available()];
                inputstream.read(abyte0);
                fileoutputstream1 = new FileOutputStream(file1);
                fileoutputstream1.write(abyte0);
                fileoutputstream1.flush();
            } catch (Exception e) {
                (new ExceptionManager()).saveException(context, NovelDB.class, e);
            } finally {
                if (inputstream != null) {
                    try {
                        inputstream.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                
                if (fileoutputstream1 != null) {
                    try {
                        fileoutputstream1.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
            
            copyInitialImageFile(context, "cache_http%3A%2F%2Fpre.yy567.net%2Fpic%2Fjpg%2F2013%2F12%2F06%2F19%2Fmmddhso_10_Gv369z.jpg");
            copyInitialImageFile(context, "cache_http%3A%2F%2Fpre.yy567.net%2Fpic%2Fjpg%2F2013%2F12%2F11%2F11%2Fcyzyhfh_10_EUjSuD.jpg");
            copyInitialImageFile(context, "cache_http%3A%2F%2Fpre.yy567.net%2Fpic%2Fjpg%2F2013%2F12%2F11%2F20%2Fmmclddyrz_10_b0MNJZ.jpg");
            copyInitialImageFile(context, "cache_http%3A%2F%2Fpre.yy567.net%2Fpic%2Fjpg%2F2013%2F12%2F11%2F20%2Fqqbqrddmmt_10_E3VwqN.jpg");
            copyInitialImageFile(context, "cache_http%3A%2F%2Fpre.yy567.net%2Fpic%2Fjpg%2F2013%2F12%2F11%2F20%2Fwypwwyx_10_JufIFz.jpg");
        }
    }

    public static void copyInitialImageFile(Context context, String s)
    {
        File file = DiskLruCache.getDiskCacheDir(context, "http");
        if (DiskLruCache.openCache(context, file, 0xa00000L) != null) {
            File file1 = new File(file, s);
            if (!file1.exists()) {
                InputStream inputstream;
                inputstream = null;
                byte abyte0[];
                FileOutputStream fileoutputstream1 = null;
                try {
                    file1.createNewFile();
                    inputstream = context.getAssets().open(s);
                    abyte0 = new byte[inputstream.available()];
                    inputstream.read(abyte0);
                    fileoutputstream1 = new FileOutputStream(file1);
                    fileoutputstream1.write(abyte0);
                    fileoutputstream1.close();
                } catch (Exception e) {
                    (new ExceptionManager()).saveException(context, NovelDB.class, e);
                } finally {
                    if (inputstream != null) {
                        try {
                            inputstream.close();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                    
                    if (fileoutputstream1 != null) {
                        try {
                            fileoutputstream1.close();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }
                
            }
        }
    }
}